.pc = $8000

.var background = LoadPicture("background.gif")

.var RGB = $012345
.var preRGB = $012345
.var coun = $00

.function convToC64Color(rgb)
{
	.if (rgb == $000000) .return $00
	.if (rgb == $ffffff) .return $01
	.if (rgb == $c42626) .return $02
	.if (rgb == $a9fff0) .return $03
	.if (rgb == $cf47ca) .return $04
	.if (rgb == $51d244) .return $05
	.if (rgb == $5a48e0) .return $06
	.if (rgb == $f7f964) .return $07
	.if (rgb == $e1b338) .return $08
	.if (rgb == $a47810) .return $09
	.if (rgb == $ff9a9a) .return $0a
	.if (rgb == $555555) .return $0b
	.if (rgb == $8c8c8c) .return $0c
	.if (rgb == $b8e75e) .return $0d
	.if (rgb == $8fabe5) .return $0e
	.if (rgb == $cdcdcd) .return $0f
}

backgroundStart:

.var rowAddrList = List()
.var rowAddr = backgroundStart

.for (var y = 0; y < background.height; y++)
{
	.eval rowAddrList.add(rowAddr)
	.for (var x = 0; x < background.width; x++)
	{
		.eval RGB =  background.getPixel(x,y)
		.if (RGB != preRGB) 
		{
			.if (preRGB != $012345)
			{
				.byte coun 
				.byte convToC64Color(preRGB)
				.eval rowAddr = rowAddr + 2
			}
			.eval preRGB = RGB
			.eval coun = 0
		}
		.eval coun++
	}
	.byte coun 
	.byte convToC64Color(preRGB)
	.eval rowAddr = rowAddr + 2
	
	.eval coun = 0
	.eval preRGB = $012345
}

backgroundRowAddrs:

.for (var i = 0; i < rowAddrList.size(); i++)
{
	.byte <rowAddrList.get(i), >rowAddrList.get(i), $00
}

.print "backgroundRowAddrs=$"+toHexString(backgroundRowAddrs)

backgroundShift:
.byte $00,$00


.pc = $9000
.define colorRam {
	.var colorRam = List()
	.for (var y=0; y<25; y++)
	{
		.for (var x=0; x<40; x++)
		{
			.eval RGB =  background.getPixel(x,y)
			.eval colorRam.add(convToC64Color(RGB))
		}
	}
}
.fill 25*40,colorRam.get(i)

fillStartBackground:
	
	ldx #$00
fsbloop:
	lda #$A0
	sta $0400,x
	sta $0500,x
	sta $0600,x
	sta $0700,x
	
	lda $9000,X
	sta $d800,X
	lda $9100,X
	sta $d900,X
	lda $9200,X
	sta $da00,X
	lda $9300,X
	sta $db00,X
	
	dex
	bne fsbloop
	
	rts

	


	